package com.jelly.web.modules.basics.sensitiveWord.controller;

import com.jelly.common.constant.GlobalConstant;
import com.jelly.common.note.OperationLog;
import com.jelly.common.util.web.AjaxPostResponse;
import com.jelly.common.web.page.LayuiTableInfo;
import com.jelly.web.share.base.controller.BaseController;
import com.jelly.web.share.base.domain.Base;
import com.jelly.web.modules.basics.sensitiveWord.domain.SensitiveWord;
import com.jelly.web.modules.basics.sensitiveWord.service.ISensitiveWordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @创建人 ql
 * @创建时间 2018-10-09 17:10
 * @项目名称 jelly
 * @功能描述: 敏感词控制器
 **/
@Controller
@RequestMapping("/admin/basics/sensitive")
public class SensitiveWordController extends BaseController {

    @Autowired
    private ISensitiveWordService sensitiveWordService;

    /**
     * 敏感词列表跳转
     * @return
     */
    @GetMapping
    public String getSensitiveWordList(){

        //获取该用户可访问的按钮详情
        getButton();

        return adminBasicsSensitiveWord("/list");

    }

    /**
     * 敏感词列表详情
     * @param sensitiveWord
     * @return
     */
    @PostMapping
    @ResponseBody
    public LayuiTableInfo getSensitiveWordList(SensitiveWord sensitiveWord){

        getPageHelper();

        return getPageHelper(sensitiveWordService.getSensitiveWordAll(sensitiveWord));
    }

    /**
     * 新增跳转
     * @return
     */
    @GetMapping("/add")
    public String addSensitiveWord(){

        return adminBasicsSensitiveWord("/add");
    }


    /**
     * 新增敏感词
     * @param sensitiveWord
     * @return
     */
    @PostMapping("/add")
    @OperationLog(name = "敏感词模块",value = GlobalConstant.ADDED)
    @ResponseBody
    public ResponseEntity<AjaxPostResponse> addSensitiveWord(SensitiveWord sensitiveWord){

        return sensitiveWordService.addSensitiveWord(sensitiveWord)?okResponse("新增成功"):errorResponse("新增失败");

    }


    /**
     * 删除敏感词
     * @param base
     * @return
     */
    @PostMapping("/delect")
    @OperationLog(name = "敏感词模块",value = GlobalConstant.DELECT)
    @ResponseBody
    public ResponseEntity<AjaxPostResponse> delectSensitiveWord(Base base){

        return sensitiveWordService.delectSensitiveWord(base.getBaseId())?okResponse("删除成功"):errorResponse("删除失败");

    }

    /**
     * 修改敏感词
     * @return
     */
    @GetMapping("/update")
    public String updateSensitiveWord(Model model, Base base){

        model.addAttribute("sensitive",sensitiveWordService.getSensitiveWordId(base.getBaseId()));

        return adminBasicsSensitiveWord("/update");

    }

    /**
     * 修改敏感词
     * @param sensitiveWord
     * @return
     */
    @PostMapping("/update")
    @OperationLog(name = "敏感词模块",value = GlobalConstant.UPDATE)
    @ResponseBody
    public ResponseEntity<AjaxPostResponse> updateSensitiveWord(SensitiveWord sensitiveWord){

        return sensitiveWordService.updatSensitiveWord(sensitiveWord)?okResponse("修改成功"):errorResponse("修改失败");

    }

}
